Skip to content

[Bugfix] Guard mm_token_type_ids kwarg in get_mrope_input_positions#35711

Merged
hmellor merged 4 commits intovllm-project:mainfrom
ROCm:akaratza_fix_multi_mod_ext_2
Mar 4, 2026
Merged

[Bugfix] Guard mm_token_type_ids kwarg in get_mrope_input_positions#35711
hmellor merged 4 commits intovllm-project:mainfrom
ROCm:akaratza_fix_multi_mod_ext_2

Conversation

@AndreasKaratzas
Copy link
Copy Markdown
Collaborator

@AndreasKaratzas AndreasKaratzas commented Mar 2, 2026

#35097 introduced passing mm_token_type_ids to model.get_rope_index() in the transformers multimodal backend. However, not all models accept this parameter. For example, Qwen2_5_VLModel.get_rope_index() does not have mm_token_type_ids in its signature nor **kwargs, causing a TypeError at inference time.

TypeError: Qwen2_5_VLModel.get_rope_index() got an unexpected keyword argument 'mm_token_type_ids'

Reproduced via:

pytest -s -v tests/models/multimodal/generation/test_common.py::test_single_image_models[qwen2_5_vl-transformers-test_case53]

Bisected to fd6de37.

Fix

Before passing mm_token_type_ids as a kwarg, inspect the signature of model.get_rope_index() to check whether it actually accepts the parameter (either explicitly or via **kwargs). If it doesn't, skip it.

cc @kenroche

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@AndreasKaratzas AndreasKaratzas requested a review from hmellor as a code owner March 2, 2026 06:29
@mergify mergify bot added the bug Something isn't working label Mar 2, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a TypeError by guarding the mm_token_type_ids keyword argument before passing it to model.get_rope_index(). The fix involves inspecting the function's signature to ensure it can accept the argument. I've suggested a performance improvement to cache the result of the signature inspection, as it's a costly operation that doesn't need to be repeated on every call.

Comment on lines +477 to +484
import inspect

sig = inspect.signature(self.model.get_rope_index)
params = sig.parameters
if "mm_token_type_ids" in params or any(
p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values()
):
kwargs["mm_token_type_ids"] = torch.cat(mm_token_type_ids)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this fix is correct, using inspect.signature on every call to get_mrope_input_positions can introduce a performance overhead, especially in a hot path. Since the signature of self.model.get_rope_index is not expected to change at runtime, this check can be performed once and the result cached. A simple way to achieve this is to use lazy initialization with hasattr to cache the check result on the first call.

            if not hasattr(self, "_get_rope_index_accepts_mm_token_type_ids"):
                import inspect

                sig = inspect.signature(self.model.get_rope_index)
                params = sig.parameters
                self._get_rope_index_accepts_mm_token_type_ids = "mm_token_type_ids" in params or any(
                    p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values()
                )

            if self._get_rope_index_accepts_mm_token_type_ids:
                kwargs["mm_token_type_ids"] = torch.cat(mm_token_type_ids)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair suggestion. Done :)

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@DarkLight1337
Copy link
Copy Markdown
Member

@hmellor can you review this?

@hmellor
Copy link
Copy Markdown
Member

hmellor commented Mar 2, 2026

Thanks for the fix @AndreasKaratzas, I think the intention in the original PR was that mm_token_type_ids would not be part of kwargs if Transformers v4 (as in CI) is installed.

I'll reproduce locally to see what options we have for fixes.

@AndreasKaratzas
Copy link
Copy Markdown
Collaborator Author

Thanks for the fix @AndreasKaratzas, I think the intention in the original PR was that mm_token_type_ids would not be part of kwargs if Transformers v4 (as in CI) is installed.

I'll reproduce locally to see what options we have for fixes.

@hmellor Would it be possible to temporarily go with this patch? We would like this test to soon be in the gating set of AMD tests :)

Copy link
Copy Markdown
Member

@hmellor hmellor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this will work for now! I'm excited for the Transformers modelling backend to be tested more on AMD!

@hmellor hmellor enabled auto-merge (squash) March 3, 2026 12:34
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 3, 2026
@hmellor hmellor disabled auto-merge March 3, 2026 12:34
@hmellor hmellor enabled auto-merge (squash) March 3, 2026 12:34
@hmellor
Copy link
Copy Markdown
Member

hmellor commented Mar 3, 2026

(I cancelled the build because it looks like it needs a rebase/merge and I can't do it myself because the PR comes form an org)

@hmellor hmellor merged commit edba150 into vllm-project:main Mar 4, 2026
58 checks passed
@AndreasKaratzas AndreasKaratzas deleted the akaratza_fix_multi_mod_ext_2 branch March 4, 2026 04:14
Copilot AI pushed a commit to machov/vllm that referenced this pull request Mar 10, 2026
avinashsingh77 pushed a commit to avinashsingh77/vllm that referenced this pull request Mar 12, 2026
wendyliu235 pushed a commit to wendyliu235/vllm-public that referenced this pull request Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants